<template>
     <div class="components-container">
         <div class="header-form">
            <div class="layui-inline">
                <label class="layui-form-label" >统计日期从</label>
                <el-date-picker v-date v-model="selectData.DpograntdateLessAndEquals" type="date" placeholder="选择日期范围" @change="btnSearch">
                </el-date-picker>到
                <el-date-picker v-date v-model="selectData.DpograntdateGreaterAndEquals" type="date" placeholder="选择日期范围" @change="btnSearch">
                </el-date-picker>
            </div>
            <el-button type="primary" :disabled="downloadLoading" @click="btnSearch" :loading="this.$store.state.isloading" >搜索</el-button>
            <el-button :disabled="this.$store.state.isloading || downloadLoading"  @click="btnRepeat">重置</el-button>
        </div>
        <div style="margin-top:10px;">
          <ul class="toolList"> 
            <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
              <el-button type="primary" :disabled="$store.state.isloading" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
            </li>
            <li>
            <el-button type="primary" :disabled="this.$store.state.isloading"  @click="exportExcel" style="margin-left:20px;margin-bottom:-10px;">导出Excel</el-button>
            </li>
          </ul>
        </div>
        <dataTable :headList="headList" :dataList="dataList" :isIndex="true" :hiddenColumn="false" :pageOrder="pageOrder" :hiddenPageOrder="true" :height="height" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
   
        <printmodal ref="printPdf"></printmodal>
        <cemeteryData ref="simpleReg" :orderType="order" @refreshData="getData"></cemeteryData>
     </div>
</template>


<script>
import dataTable from "@/components/Table/DataTable";
import cemeteryData from "./tombsUseMain";

import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import printmodal from "@/components/Pdf/Print";
import { PRINT } from "@/components/Pdf/PDF.js";
const INFO = "详情";
const EXPORT = "导出";
const ADD = '新增';
export default {
  name: "iceuseSearch",
  mixins: [manage],
  data() {
    return {
      selectData: {
        DpograntdateLessAndEquals: null,  
        DpograntdateGreaterAndEquals: null, 
        CdhCodnameEqual: null,  
        CdhdriverEqual: null,  
      },
      height: "620",
      downloadLoading:false,
      Manufactor: [],
      cdhTypes: [],
      drivers: [],
      AlldataList: [],
    };
  },
  methods: {
    exportExcel() {
      var startTime;
      var endTime;
      if(this.selectData.DpograntdateLessAndEquals){
        startTime = this.selectData.DpograntdateLessAndEquals.toLocaleDateString();
      }else{
        startTime = '空';
      }
      if(this.selectData.DpograntdateGreaterAndEquals){
        endTime = this.selectData.DpograntdateGreaterAndEquals.toLocaleDateString();
      }else{
        endTime = '空';
      }
      var header = '丧葬用品明细表' + '(' + startTime + '--' + endTime + ')';
       if (this.AlldataList.length === 0){
          this.$message.error("无导出数据！");
          return;
      }
      this.downloadLoading = true;
      require.ensure([], () => {
        const { export_json_to_excel } = require("@/vendor/Export2Excel");
        export_json_to_excel(this.headList, this.AlldataList, header);
        this.downloadLoading = false;
      });
    },
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case INFO:
        //   this.$refs.simpleReg.open(this.order, this.currentRow.TMMID);
          break;
        case EXPORT:
          this.$refs.printPdf.report(PRINT.PDFICEDISPATCHSEARCH,this.getDataC());
          break;
        default:
      }
    },
    //获取所属厂家
    QueryVdr(){
        apiBase.DoService(
            {},
            apiBase.getApiAdress().Depot.QueryVdrByZC,
            res => {
                this.Manufactor = res.data.content.OutData;
            }
        )
    },
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetFuneralThingsAdjustLibraryReportColums,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    getDataC(){
      let Data = JSON.parse(JSON.stringify(this.selectData));
      let data = {
        PageIndex: -1,
        PageSize: 0,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      return data;
    },
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      if(this.selectData.DpograntdateLessAndEquals){
        Data.DpograntdateLessAndEquals =  formatDate(Data.DpograntdateLessAndEquals, "yyyyMMdd");
      }
      if(this.selectData.DpograntdateGreaterAndEquals){
        Data.DpograntdateGreaterAndEquals =  formatDate(Data.DpograntdateGreaterAndEquals, "yyyyMMdd");
      }
      let data = {   
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(data, apiBase.getApiAdress().Depot.QueryAdjustLibraryDetaile, res => {
        this.dataList = res.data.content.OutData;
        this.pageOrder.totalNum = res.data.content.RecordCount;
        this.getAllData();
      });
    },
    getAllData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      if(this.selectData.DpograntdateLessAndEquals){
        Data.DpograntdateLessAndEquals =  formatDate(Data.DpograntdateLessAndEquals, "yyyyMMdd");
      }
      if(this.selectData.DpograntdateGreaterAndEquals){
        Data.DpograntdateGreaterAndEquals =  formatDate(Data.DpograntdateGreaterAndEquals, "yyyyMMdd");
      }
      let data = {   
        PageIndex: -1,
        PageSize: 0,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(data, apiBase.getApiAdress().Depot.QueryAdjustLibraryDetaile, res => {
        this.AlldataList = res.data.content.OutData;
      });
    },
    //获取派车类别
    getSendCdhTypes() {
        let data = {};
        apiBase.DoService(
            data,
            apiBase.getApiAdress().Code.GetSendCdhType,
            res => {
                let cdhTypeData = res.data.content,
                    legendsCdhData = cdhTypeData.map(item => ({
                        label: item.CodeName,
                        value: item.CodeValue
                    }));
                this.cdhTypes = legendsCdhData;
            }
        );
    },
     //获取司机
    getDrivers() {
        let data = {};
        apiBase.DoService(
            data,
            apiBase.getApiAdress().Staff.QueryDriver,
            res => {
                let driverData = res.data.content,
                    legendsDrivers = driverData.map(item => ({
                        label: item.STANAME,
                        value: item.STAID
                    }));
                this.drivers = legendsDrivers;
            }
        );
    },

    btnShow(btn){
      switch (btn) {
          case '导出':
            return true;
            break;
          case '详情':
            return true;
            break;
          default: return false;
        }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {
        DpograntdateLessAndEquals: null,  
        DpograntdateGreaterAndEquals: null, 
        CdhCodnameEqual: null,  
        CdhdriverEqual: null,  
      };
      this.getData();
    }
  },
  mounted() {

  },
  components: {
    dataTable,
    cemeteryData,
    printmodal
  },
  created() {
    this.getColumns();//获取headerlist
    this.getData();//获取数据
    this.QueryVdr();
    this.getSendCdhTypes();
    this.getDrivers();
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>

